/********************************************
 * 功能说明: 
 * 模块名称: 
 * 系统名称: 
 * 软件版权: Frank
 * 系统版本: 1.0.0
 * 开发人员: Frank
 * 开发时间: 2019/12/9 11:55
 * 审核人员: 
 * 相关文档: 
 * 修改记录: 修改日期 修改人员 修改说明
 *********************************************/
package com.spring.arch.uaa.model;

import com.spring.arch.common.jpa.model.AbstractLogicalModel;
import com.spring.arch.uaa.enums.ProjectStatus;
import com.spring.arch.uaa.enums.ProjectType;
import com.spring.arch.common.jpa.model.AbstractLogicalModel;
import com.spring.arch.uaa.enums.ProjectStatus;
import com.spring.arch.uaa.enums.ProjectType;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import javax.persistence.*;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.util.UUID;

/**
 * 项目信息
 * 一个租户{@linkplain Tenant} 对应多个项目
 * 一个项目对应多个数据源配置{@linkplain ProjectDatasource}
 * @author Frank
 * @version 1.0.0.1
 * @since 2019/12/9 11:55
 */
@NoArgsConstructor
@Getter
@Setter
@Entity
@Table(name = "project")
public class Project extends AbstractLogicalModel {

    private static final long serialVersionUID = 1131334607853593962L;

    /**
     * 所属租户
     */
    @NotNull
    @ManyToOne(fetch = FetchType.LAZY)
    private Tenant tenant;

    /**
     * 项目根组织
     */
    @NotNull
    @OneToOne(fetch = FetchType.LAZY)
    private Organization rootOrganization;


    /**
     * 数据源配置
     */
    @NotNull
    @OneToOne(fetch = FetchType.LAZY)
    private ProjectDatasource datasource;

    /**
     * 项目编码
     */
    @NotBlank
    @Size(max = 32)
    @Column(nullable = false, unique = true)
    private String code;

    /**
     * 项目名称
     */
    @NotBlank
    @Size(max = 64)
    @Column(nullable = false, unique = true)
    private String name;

    /**
     * 项目类型
     */
    @NotNull
    @Enumerated(EnumType.STRING)
    @Column(length = 32)
    private ProjectType type;

    /**
     *区域id
     */
    @Column(length = 16)
    private UUID areaId;

    /**
     * 详细地址
     */
    @NotBlank
    @Size(max = 255)
    @Column(nullable = false)
    private String address;

    /**
     * 备注
     */
    @Size(max = 255)
    private String remarks;

    /**
     * 项目状态
     */
    @NotNull
    @Enumerated(EnumType.STRING)
    @Column(length = 32)
    private ProjectStatus status;

    public Project(@NotNull Tenant tenant, @NotNull Organization rootOrganization, @NotNull ProjectDatasource datasource, @NotBlank @Size(max = 32) String code, @NotBlank @Size(max = 64) String name, @NotNull ProjectType type, @NotBlank @Size(max = 255) String address, @NotNull ProjectStatus status) {
        this.tenant = tenant;
        this.rootOrganization = rootOrganization;
        this.datasource = datasource;
        this.code = code;
        this.name = name;
        this.type = type;
        this.address = address;
        this.status = status;
    }
}
